//
//  MLWaterSurface.m
//  WaterProof
//
//  Created by victor0321 on 12/1/9.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "MLWaterSurface.h"


@implementation MLWaterSurface

+(id) waterSurface:(NSInteger)num
{
	return [[[self alloc] initWithWaterImage:(NSInteger)num] autorelease];
}

-(id) initWithWaterImage:(NSInteger)num{
    
    if(self = [super init])
    {
        
        NSMutableArray* frames = [NSMutableArray arrayWithCapacity:6];
        if(num%2 == 0)
        {
            for (int i = 1; i <= 6; i++)
            {
                NSString* file = [NSString stringWithFormat:@"water_surface%i.png", i];
                CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
                CGSize texSize = texture.contentSize;
                CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
                CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
                [frames addObject:frame];
            }
        }
        else
        {
            for (int i = 6; i >= 1; i--)
            {
                NSString* file = [NSString stringWithFormat:@"water_surface%i.png", i];
                CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
                CGSize texSize = texture.contentSize;
                CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
                CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
                [frames addObject:frame];
            }
        }
        CCAnimation* anim = [CCAnimation animationWithFrames:frames delay:0.2f];
        CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
        CCRepeatForever* repeatWater = [CCRepeatForever actionWithAction:animate];
        [self runAction:repeatWater];

    }
    return self;
}

-(void) dealloc
{
	
	// don't forget to call "super dealloc"
	[super dealloc];
}


@end
